/**
 * Created by 王清腾 on 2017/9/28.
 */
/**
 * Created by isec on 2017/2/24.
 */


var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var autoprefixer = require('gulp-autoprefixer');
var connect = require('gulp-connect');
var spritemith = require('gulp.spritesmith');
var uglifycss = require('gulp-uglifycss');
var concat = require('gulp-concat');
var htmlmin = require('gulp-htmlmin');
var postcss = require('gulp-postcss');
var px2rem = require('postcss-px2rem');
var uglify = require('gulp-uglify');

gulp.task('connect', function() {
    connect.server();
});

gulp.task('server', ['connect']);

gulp.task('style', function () {
    var processors = [px2rem({remUnit: 75})];
    sass('src/scss/index.scss', {})
        .on('error', sass.logError)
        .pipe(autoprefixer({
            browsers: ['last 7 versions'],
            cascade: false
        }))
        .pipe(gulp.dest('dist/css'))
        .pipe(postcss(processors))
        .pipe(uglifycss({
            "maxLineLen": 2000,
            "uglyComments": true
        }))
        .pipe(concat('index.min.css'))
        .pipe(gulp.dest('static/css'))
});

gulp.task('minify', function() {
    return gulp.src('*.html')
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest('dist'));
});

gulp.task('miniJs', function () {
    return gulp.src('static/region/*.js')
        .pipe(concat('region.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'))
})

gulp.task('miniAwardJs', function () {
    return gulp.src('src/js/*.js')
        .pipe(concat('vue.award.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'))
})


gulp.task('sprite',function(){
    gulp.src('src/sprite/*.png')
        .pipe(spritemith({
            imgName: 'images/sprite.png',//保存合并后图片的地址
            cssName: 'src/scss/sprite.css',//保存合并后对于css样式的地址
            padding:5,//合并时两个图片的间距
            //algorithm: 'binary-tree',//注释1
            //cssTemplate:"dist/css/handlebarsStr.css"//注释2
        }))
        .pipe(gulp.dest(''));
});
gulp.task('sprite2',function(){
    gulp.src('src/sprite2/*.png')
        .pipe(spritemith({
            imgName: 'images/sprite2.png',//保存合并后图片的地址
            cssName: 'src/scss/sprite2.css',//保存合并后对于css样式的地址
            padding:5,//合并时两个图片的间距
            // algorithm : 'left-right',
            // algorithm :{
            //     sort: true
            // }
            // sort : true
            //algorithm: 'binary-tree',//注释1
            //cssTemplate:"dist/css/handlebarsStr.css"//注释2
        }))
        .pipe(gulp.dest(''));
});